package com.ruoyi.web.controller.devicedata;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.domain.insect.InsectRecord;
import com.ruoyi.web.pojo.request.insect.InsectHistoryDataRequest;
import com.ruoyi.web.pojo.request.insect.InsectSumDataRequest;
import com.ruoyi.web.pojo.vo.insect.InsectCountDataVO;
import com.ruoyi.web.pojo.vo.insect.InsectHistoryDataVO;
import com.ruoyi.web.service.insect.InsectRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Api(value = "虫情识别数据",tags = "虫情识别数据")
@RestController
@RequestMapping("/insect-record")
public class InsectRecordController extends BaseController {

    @Autowired
    private InsectRecordService insectRecordService ;

    @ApiOperation("首页虫情历史数据")
    @GetMapping("/getHistoryHandlerData")
    public R getHistoryHandlerData(InsectHistoryDataRequest request)
    {
        InsectHistoryDataVO datas = insectRecordService.getHistoryHandlerData(request);
        return R.ok(datas);
    }

    @ApiOperation("虫情数据页-统计设备识别虫数量")
    @GetMapping("/getSpInsectCountData")
    public R<List<InsectCountDataVO>> getSpInsectCountData(InsectSumDataRequest request)
    {
        List<InsectCountDataVO> countData = insectRecordService.getSpInsectCountData(request);
        return R.ok(countData);
    }

    @ApiOperation("虫情数据页-底部-虫情统计数据")
    @GetMapping("/getHistoryData")
    public R<List<InsectRecord>> getHistoryData(InsectHistoryDataRequest request)
    {
        List<InsectRecord> historyData = insectRecordService.getHistoryData(request);
        return R.ok(historyData);
    }


    @ApiOperation("虫情数据页-识别种类,识别数量")
    @GetMapping("/insectStatistics")
    public R<InsectCountDataVO> insectStatistics(InsectSumDataRequest request)
    {
        InsectCountDataVO vo = insectRecordService.insectStatistics(request);
        return R.ok(vo);
    }


    @ApiOperation("虫情数据页-底部-导出虫情统计数据")
    @GetMapping("/exportHistoryData")
    public AjaxResult exportHistoryData(InsectHistoryDataRequest request)
    {
        List<InsectRecord> historyData = insectRecordService.getHistoryData(request);
        InsectRecord.buildNo(historyData);
        ExcelUtil<InsectRecord> util = new ExcelUtil<>(InsectRecord.class);
        return util.exportExcel(historyData, "虫情统计数据");
    }




}
